package com.gxa.question.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.common.R;
import com.gxa.common.entity.platform_maintenance_service1001.QuestionClassification;
import com.gxa.question.mapper.QuestionClassificationMapper;
import com.gxa.question.service.QuestionClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service

public class QuestionClassificationServiceImpl  extends ServiceImpl<QuestionClassificationMapper, QuestionClassification> implements QuestionClassificationService {

    @Autowired
    private QuestionClassificationMapper questionClassificationMapper;
    @Cacheable(cacheNames = "BadWeatherList",key = "#currentPage+'-'+#pageSize")
//  @CacheEvict(value = "BadWeather",allEntries=true) 每次都会清除缓存
    @Override
    public R questionClassificationByPage(Integer currentPage, Integer pageSize) {
        R r = new R();
        QueryWrapper<QuestionClassification> queryWrapper = new QueryWrapper<>();
        Page<QuestionClassification> page = new Page<>(currentPage,pageSize);
        Page<QuestionClassification> reportManagementPage = questionClassificationMapper.selectPage(page, queryWrapper);
        r.setMessage("按照分页查询成功");
        r.setCode(200);
        r.setData(reportManagementPage);

        return r;
    }

    @Override
    public R addQuestionClassification(QuestionClassification questionClassification) {
        R r = new R();
        int result = questionClassificationMapper.insert(questionClassification);
        if(result > 0 ){
            r.setCode(200);
            r.setMessage("添加成功");
            r.setData(result);
        }else{
            r.setCode(500);
            r.setMessage("添加失败");
        }

        return r;
    }

    @Override
    public R updateQuestionClassification(QuestionClassification questionClassification) {

        R r= new R();
        int result = questionClassificationMapper.updateById(questionClassification);
        if(result > 0 ){
            r.setCode(200);
            r.setMessage("修改成功");
            r.setData(result);
        }else{
            r.setCode(500);
            r.setMessage("修改失败");
        }
        return r;
    }

    @Override
    public R delQuestionClassificationByIds(List<Integer> ids) {
        R r= new R();
        int result = questionClassificationMapper.delQuestionClassificationByIds(ids);
        if(result > 0 ){
            r.setCode(200);
            r.setMessage("删除成功");
            r.setData(result);
        }else{
            r.setCode(500);
            r.setMessage("删除失败");
        }
        return r;
    }

    @Override
    public R selectQuestionClassification(QuestionClassification questionClassification) {
       R r = new R();
       List<QuestionClassification> questionClassificationList = questionClassificationMapper.selectQuestionClassification(questionClassification);
       r.setCode(200);
       r.setMessage("按照条件查询成功");
       r.setData(questionClassificationList);
       return r;
    }

    @Override
    public R selectQuestionClassificationByQuestionClassification(String question_classification) {

        R r = new R();
        QuestionClassification questionClassification = questionClassificationMapper.selectQuestionClassificationByQuestionClassification(question_classification);
        System.out.println("========="+questionClassification);
        r.setCode(200);
        r.setMessage("查询成功");
        r.setData(questionClassification);
        return r;
    }
}
